home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.3 KB | 113 lines | [TEXT/CWIE] |
- // Menu.cp
-
- #ifndef Menu_h
- #include "Menu.h"
- #endif
- #ifndef MenuBar_h
- #include "MenuBar.h"
- #endif
- #ifndef MenuSection_h
- #include "MenuSection.h"
- #endif
- #ifndef MinMax_h
- #include "MinMax.h"
- #endif
-
- Menu::Menu( MenuID id, ConstPString title )
- : MenuObject( id, title ),
- sectionCount( 0 ),
- itemCount( 0 ),
- link( this )
- {
- for ( uint16 i = 0; i < maxSections; i++ )
- {
- sections[i] = 0;
- items[i] = 0;
- }
- MenuBar::The().Add( link, afterEnd );
- }
-
- Menu::Menu( ResourceID resource )
- : MenuObject( resource ),
- sectionCount( 0 ),
- itemCount( 0 ),
- link( this )
- {
- for ( uint16 i = 0; i < maxSections; i++ )
- {
- sections[i] = 0;
- items[i] = 0;
- }
- MenuBar::The().Add( link, afterEnd );
- }
-
- void Menu::AddFixedSection( MenuSection& section, uint16 length )
- {
- Assert( sectionCount < maxSections );
- Assert( length > 0 );
- Assert( length < maxSections );
- Assert( itemCount + length < maxSections );
-
- Assert( sections[ sectionCount ] == 0 );
- sections[ sectionCount++ ] = §ion;
-
- uint16 firstItem = itemCount;
- itemCount += length;
- for ( uint32 i = firstItem; i < itemCount; i++ )
- {
- Assert( items[ i ] == 0 );
- items[ i ] = §ion;
- }
- }
-
- void Menu::AddExtensibleSection( MenuSection& section )
- {
- Assert( sectionCount < maxSections );
- Assert( itemCount < maxSections );
-
- Assert( sections[ sectionCount ] == 0 );
- sections[ sectionCount++ ] = §ion;
-
- uint16 firstItem = itemCount;
- itemCount = maxSections;
- for ( uint32 i = firstItem; i < itemCount; i++ )
- {
- Assert( items[ i ] == 0 );
- items[ i ] = §ion;
- }
- }
-
- void Menu::Prepare()
- {
- // Make sure we've added all our items
- Assert( itemCount == maxSections || itemCount == Length() );
- for ( uint32 i = 0; i < sectionCount; i++ )
- {
- Assert( sections[i] != 0 );
- sections[i]->Prepare();
- }
-
- EnableIfItemsEnabled();
- }
-
- void Menu::Choose( uint16 item )
- {
- Assert( item < Length() );
-
- uint32 sectionNumber = item;
- if ( sectionNumber >= maxSections )
- sectionNumber = maxSections;
-
- Assert( sectionNumber < itemCount );
- Assert( items[ sectionNumber ] != 0 );
- MenuSection& section( *items[ sectionNumber ] );
-
- Assert( item >= section.FirstItem() );
- Assert( item < section.FirstItem() + section.MaxLength() );
-
- section.Choose( item - section.FirstItem() );
- }
-
- #include "ListLink.cp"
- #include "ListOf.cp"
-